<template>
	<view v-if="orderInfo" class="content">
		<view class="wid100 bacFFF">
			<view class="wid90 mar dis disAl disJuC" style="height: 100rpx;">
				<view class="dis fowe600 foSi18">
					<view class="textCen">
						<view class="dis disAl disJuC borRad50 coFFF mar"
							:style="orderInfo.status >= 0?'background: #37BCC3;':'background: #A6A6A6;'"
							style="width: 35rpx;height: 35rpx;line-height: 38rpx;">1</view>
						<view class="mar-top10" style="color: #666565;">已下单</view>
					</view>
					<view style="width: 83rpx;height: 1rpx;background: #A6A6A6;margin-left: -6rpx;margin-top: 16rpx;">
					</view>
					<view class="textCen" style="margin-left: -6rpx;">
						<view class="dis disAl disJuC borRad50 coFFF mar"
							:style="orderInfo.status >= 2?'background: #37BCC3;':'background: #A6A6A6;'"
							style="width: 35rpx;height: 35rpx;line-height: 38rpx;">2</view>
						<view class="mar-top10" style="color: #666565;">待接单</view>
					</view>
					<view style="width: 83rpx;height: 1rpx;background: #A6A6A6;margin-left: -6rpx;margin-top: 16rpx;">
					</view>
					<view class="textCen" style="margin-left: -6rpx;">
						<view class="dis disAl disJuC borRad50 coFFF mar"
							:style="orderInfo.status >= 2 && orderInfo.collect_clerk_id != 0?'background: #37BCC3;':'background: #A6A6A6;'"
							style="width: 35rpx;height: 35rpx;line-height: 38rpx;">3</view>
						<view class="mar-top10" style="color: #666565;">待收衣</view>
					</view>
					<view style="width: 83rpx;height: 1rpx;background: #A6A6A6;margin-left: -6rpx;margin-top: 16rpx;">
					</view>
					<view class="textCen" style="margin-left: -6rpx;">
						<view class="dis disAl disJuC borRad50 coFFF mar"
							:style="orderInfo.status >= 3 && (orderInfo.status != 9 && orderInfo.status != 10)?'background: #37BCC3;':'background: #A6A6A6;'"
							style="width: 35rpx;height: 35rpx;line-height: 38rpx;">4</view>
						<view class="mar-top10" style="color: #666565;">清洗中</view>
					</view>
					<view style="width: 83rpx;height: 1rpx;background: #A6A6A6;margin-left: -6rpx;margin-top: 16rpx;">
					</view>
					<view class="textCen" style="margin-left: -6rpx;">
						<view class="dis disAl disJuC borRad50 coFFF mar"
							:style="orderInfo.status >= 4 && (orderInfo.status != 9 && orderInfo.status != 10)?'background: #37BCC3;':'background: #A6A6A6;'"
							style="width: 35rpx;height: 35rpx;line-height: 38rpx;">5</view>
						<view class="mar-top10" style="color: #666565;">配送中</view>
					</view>
					<view style="width: 83rpx;height: 1rpx;background: #A6A6A6;margin-left: -6rpx;margin-top: 16rpx;">
					</view>
					<view class="textCen" style="margin-left: -6rpx;">
						<view class="dis disAl disJuC borRad50 coFFF mar"
							:style="orderInfo.status >= 7 && (orderInfo.status != 9 && orderInfo.status != 10)?'background: #37BCC3;':'background: #A6A6A6;'"
							style="width: 35rpx;height: 35rpx;line-height: 38rpx;">6</view>
						<view class="mar-top10" style="color: #666565;">已完成</view>
					</view>
				</view>
			</view>
		</view>
		<view class="wid90 mar bacFFF mar-top30 borRad20" style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);">
			<view class="wid90 mar dis disAl fowe800 foSi30" style="height: 74rpx;">配送信息</view>
			<view class="wid100 xia"></view>
			<view class="wid90 mar dis disAl" style="padding: 25rpx 0;">
				<image src="../../static/shohuo2.png" style="width: 30rpx;height: 46rpx;"></image>
				<view class="mar-left30 foSi25">
					<view class="dis disAl ">
						<view>{{orderInfo.address_take.name}}</view>
						<view class="mar-left30" @click="callPhone(orderInfo.address_take.phone)">
							{{orderInfo.address_take.phone}}</view>
					</view>
					<view class="mar-top20" style="color: #8B8B8B;">
						{{orderInfo.address_take.address+orderInfo.address_take.content}}</view>
				</view>
			</view>
			<view class="wid100 xia"></view>
			<view class="wid90 mar dis disAl" style="padding: 25rpx 0;">
				<image src="../../static/shohuo3.png" style="width: 30rpx;height: 46rpx;"></image>
				<view class="mar-left30 foSi25">
					<view class="dis disAl ">
						<view>{{orderInfo.address_give.name}}</view>
						<view class="mar-left30" @click="callPhone(orderInfo.address_give.phone)">
							{{orderInfo.address_give.phone}}</view>
					</view>
					<view class="mar-top20" style="color: #8B8B8B;">
						{{orderInfo.address_give.address+orderInfo.address_give.content}}</view>
				</view>
			</view>
		</view>
		<view v-if="orderInfo.status >= 2 && orderInfo.collect_clerk_id == yuan_userinfo.id"
			class="wid90 mar bacFFF mar-top30 borRad20" style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);">
			<view class="wid90 mar dis disAl fowe800 foSi30" style="height: 74rpx;">收衣信息</view>
			<view class="wid100 xia"></view>
			<view class="wid90 mar" style="padding: 25rpx 0;">
				<view class="wid100 dis disAl disJuB" style="padding: 40rpx 0;">
					<view class="wid50 dis disAl fowe800 foSi30" style="height: 74rpx;">收衣照片</view>
					<view class="dis disAl" @click="collectImage()" v-if="orderInfo.status == 2">
						<view class="foSi25 mar-right10" style="color: #8B8B8B;;">上传照片</view>
						<image src="../../static/upImage.png" style="width: 35rpx;height: 32rpx;"></image>
					</view>
					<!-- <image v-if="collect_photo" :src="url+collect_photo" style="width: 80rpx;height: 80rpx;" @click="collectImage()"></image> -->
				</view>
				<view class="mar-left30 foSi25" style="color:#8B8B8B;">
					取到衣物后，请上衣物照片。
				</view>
				<view v-if="collect_photo.length > 0" class="wid100 " style="padding: 30rpx 0;">
					<view class="fowe600 foSi25 mar-right20 mar-bott20">衣物照片：</view>
					<image v-for="(item,index) in collect_photo" :src="url+item" style="width: 120rpx;height: 120rpx;"
						:style="(index + 1) % 4 == 0?' margin-right:0rpx;':' margin-right:40rpx;'"
						@click="clickImg(index,0)"></image>
				</view>
				<view class="textCen fowe800 foSi30 mar-top40" @click="wcsy" v-if="orderInfo.status == 2">
					完成收衣
				</view>
			</view>
		</view>
		<view v-if="orderInfo.status >= 4" class="wid90 mar bacFFF mar-top30 borRad20"
			style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);">
			<view class="wid90 mar dis disAl fowe800 foSi30" style="height: 74rpx;">配送详细信息</view>
			<view class="wid100 xia"></view>
			<view class="wid90 mar" style="padding: 25rpx 0;">
				<view class="wid100 mar dis disAl disJuB" style="padding: 40rpx 0;">
					<view class="wid50 dis disAl fowe800 foSi30" style="height: 74rpx;">配送照片</view>
					<view class="dis disAl" @click="sendImage()" v-if="orderInfo.status == 4">
						<view class="foSi25 mar-right10" style="color: #8B8B8B;;">上传照片</view>
						<image src="../../static/upImage.png" style="width: 35rpx;height: 32rpx;"></image>
					</view>
				</view>
				<view class="mar-left30 foSi25" style="color:#8B8B8B;">
					请上传衣物送达照片，存放寄存点或超市的拍摄衣物存放位置。
				</view>
				<view v-if="collect_photo.length > 0" class="wid100 " style="padding: 30rpx 0;">
					<view class="fowe600 foSi25 mar-right20 mar-bott20">衣物照片：</view>
					<image v-for="(item,index) in send_photo" :src="url+item" style="width: 120rpx;height: 120rpx;"
						:style="(index + 1) % 4 == 0?' margin-right:0rpx;':' margin-right:40rpx;'"
						@click="clickImg(index,1)"></image>
				</view>
				<view class="textCen fowe800 foSi30 mar-top40" @click="wcps" v-if="orderInfo.status == 4">
					完成配送
				</view>
			</view>
		</view>
		<view class="wid90 mar bacFFF mar-top30 borRad20"
			style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1); margin-bottom: 60px;">
			<view class="wid90 mar dis disAl" style="height: 96rpx;">
				<image src="../../static/shangjia_icon.png" style="width: 39rpx;height: 35rpx;"></image>
				<view class="fowe800 foSi35 mar-left20">{{orderInfo.gasstation.name}}</view>
			</view>
			<view class="wid100 xia"></view>
			<block v-for="(item, index) in JSON.parse(orderInfo.goods_info)" :key="index">
				<view class="wid90 mar dis disAl " style="padding: 25rpx 0;">
					<view class="wid25" style="height: 115rpx;">
						<image :src="url+item.goods_pic" class="hei100" style="width: 115rpx;"></image>
					</view>
					<view style="width: 75%;">
						<view class="foSi25 fowe600">{{item.goods_name}}</view>
						<view class="mar-top30 dis disAl disJuB foSi25">
							<view style="color: #A8AAAA;">×{{item.nums}}</view>
							<view class="fowe600" style="color: #37BCC3;">¥{{item.money}}</view>
						</view>
					</view>
				</view>
				<view class="wid100 xia"></view>
			</block>
			<view class="wid90 mar " style="padding: 30rpx 0;">
				<view class="fowe600 foSi25 mar-right20">衣物照片：</view>
				<image v-for="(item,index) in orderInfo.photo" :src="url+item" style="width: 120rpx;height: 120rpx;"
					:style="(index + 1) % 4 == 0?' margin-right:0rpx;':' margin-right:40rpx;'"
					@click="clickImg(index,2)"></image>
			</view>
			<view class="wid100 xia"></view>
			<view class="wid90 mar mar-top30 foSi25 fowe600">
				<view v-if="orderInfo.collect_clerk_id != 0">接单人： {{orderInfo.collect_clerk_user.name}} /
					{{orderInfo.collect_clerk_user.mobile}}</view>
				<view class="mar-top20">订单金额： ¥{{orderInfo.total_amount}}</view>
				<view class="mar-top20">优惠券抵扣： ¥{{orderInfo.coupon_money}}</view>
				<view class="mar-top20">实际支付： <span style="color: #37BCC3;">¥{{orderInfo.pay_amount}}</span></view>
				<view class="dis disAl mar-top20">
					<view class="mar-right20">订单编号： {{orderInfo.ordernum}}</view>
					<image src="../../static/fuzhi1.png" @click="fuzhi(orderInfo.ordernum)"
						style="width: 24rpx;height: 26rpx;"></image>
				</view>
				<view class="mar-top20">提交时间：{{orderInfo.createtime}}</view>
				<view class="mar-top20">预约时间：{{dateFormat(orderInfo.reservation_time,1)}}~{{dateFormat(orderInfo.reservation_timeend,2)}}</view>
				<view class="mar-top20">支付方式：微信支付</view>
				<view class="mar-top20">备注：{{orderInfo.remarks?orderInfo.remarks:'无'}}</view>
				<view style="height: 30rpx;"></view>
			</view>
		</view>
		<view style="height: 50rpx;"></view>

		<view v-if="orderInfo.status == 2 && orderInfo.collect_clerk_id == 0" class="" @click="qiang(orderInfo.id)"
			style="z-index: 99999;
	background: #37BCC3;
	border-radius: 50rpx;
	text-align: center;
	line-height: 100rpx;
	position: fixed;
	  width: 500rpx;
	  height: 100rpx;
	  bottom: 0%;
	  left: 50%;
	  transform: translate(-50%, -50%);
	  color: #fff;
	  font-size:40rpx;
	">
			抢单
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				id: 0,
				orderInfo: '',
				collect_photo: [],
				send_photo: [],
				yuan_userinfo: uni.getStorageSync('yuan_userinfo')
			}
		},
		onLoad(option) {
			// this.yuan_userinfo = uni.getStorageSync('yuan_userinfo');
			this.id = option.id
			this.getList()
		},
		onShow() {},
		methods: {
			dateFormat(time,type) {
				var date = new Date(time*1000);
				let year = date.getFullYear();
				// 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
				let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
				let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
				let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
				let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
				let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				// 拼接
				if(type == 1){
					return year + "年" + month + "月" + day + "日" + hours + ":" + minutes;
				}else{
					return hours + ":" + minutes;
				}
				// return year + "-" + month + "-" + day;
			},
			qiang(id) {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_pay_clerk_order_qiang',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						id: id,
						collect_clerk_id: uni.getStorageSync('yuan_userinfo').id
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							uni.showToast({
								title: result.msg,
								icon: 'success', //将值设置为 success 或者 ''
								duration: 2000 //持续时间为 2秒
							})
							that.getList()
						}
					}
				})
			},
			callPhone(tel) {
				uni.makePhoneCall({
					phoneNumber: tel
				})
			},
			clickImg(index, type) { //type 0收衣图片 1配送图片 2衣物照片
				var that = this;
				console.log(type);
				// console.log(that.orderInfo.photo , "能打印出图片合集吗");
				if (type == 0) {
					var url = that.collect_photo.map(item => {
						// console.log(item , "能打印出图片链接吗");
						return that.url + item;
					})
				}
				if (type == 1) {
					var url = that.send_photo.map(item => {
						// console.log(item , "能打印出图片链接吗");
						return that.url + item;
					})
				}
				if (type == 2) {
					var url = that.orderInfo.photo.map(item => {
						// console.log(item , "能打印出图片链接吗");
						return that.url + item;
					})
				}
				uni.previewImage({
					current: index, //需要预览的图片http链接列表，多张的时候，url直接写在后面就行了
					urls: url, // 当前显示图片的http链接，默认是第一个
				})
			},
			fuzhi(value) {
				//提示模板
				uni.showModal({
					content: value, //模板中提示的内容
					confirmText: '复制内容',
					success: () => { //点击复制内容的后调函数
						//uni.setClipboardData方法就是讲内容复制到粘贴板
						uni.setClipboardData({
							data: value, //要被复制的内容
							success: () => { //复制成功的回调函数
								uni.showToast({ //提示
									title: '复制成功'
								})
							}
						});
					},
				});
			},
			getList() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_pay_clerk_order_info',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						id: that.id,
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.collect_photo = result.data.collect_photo != null ? result.data.collect_photo
								.split(',') : [];
							that.send_photo = result.data.send_photo != null ? result.data.send_photo.split(',') :
								[];
							that.orderInfo = result.data
							that.orderInfo.photo = that.orderInfo.photo.split(",");
						}
					}
				})
			},
			//完成收衣
			wcsy() {
				var that = this;
				if (that.collect_photo.length == 0) {
					uni.showToast({
						title: '请上传衣物照片',
						icon: 'none',
						duration: 2000
					})
					return;
				}
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_pay_order_collect',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						id: that.id,
						clerk_id: uni.getStorageSync('yuan_userinfo').id,
						collect_photo: that.collect_photo
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							// 页面重载
							const pages = getCurrentPages()
							console.log(pages, 'pages是啥');
							// 声明一个pages使用getCurrentPages方法
							const curPage = pages[pages.length - 1]
							// 声明一个当前页面
							curPage.onLoad(curPage.options) // 传入参数
							curPage.onShow()
							curPage.onReady()
						}
					}
				})
			},
			//完成配送
			wcps() {
				var that = this;
				console.log(that.send_photo);
				if (that.send_photo.length == 0) {
					uni.showToast({
						title: '请上传衣物送达照片',
						icon: 'none',
						duration: 2000
					})
					return;
				}
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_pay_order_send',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						id: that.id,
						clerk_id: uni.getStorageSync('yuan_userinfo').id,
						send_photo: that.send_photo
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							// 页面重载
							const pages = getCurrentPages()
							// 声明一个pages使用getCurrentPages方法
							const curPage = pages[pages.length - 1]
							// 声明一个当前页面
							curPage.onLoad(curPage.options) // 传入参数
							curPage.onShow()
							curPage.onReady()
						}
					}
				})
			},
			//上传图片
			collectImage() {
				var that = this
				uni.chooseImage({
					count: 9,
					success: (res) => {
						for (let i = 0; i < res.tempFilePaths.length; i++) {
							that.shangchuan(res.tempFilePaths[i], 0)
						}
					},
				})
			},
			//上传图片
			sendImage() {
				var that = this
				uni.chooseImage({
					count: 9,
					success: (res) => {
						console.log(res);
						for (let i = 0; i < res.tempFilePaths.length; i++) {
							that.shangchuan(res.tempFilePaths[i], 1)
						}
					},
				})
			},
			shangchuan(tempFilePaths, type) {
				var that = this
				uni.uploadFile({
					url: that.global.url + '/api/qianyu_petrol/gasstation_common_image',
					header: {
						'site-id': that.global.site_id,
						"token": uni.getStorageSync('token'),
					}, //请求token	
					filePath: tempFilePaths,
					name: 'file',
					success: (res) => {
						var apiresult = JSON.parse(res.data)
						console.log(apiresult);
						if (apiresult.code == 1) {
							if (type == 0) {
								that.collect_photo.push(apiresult.data.url);
							} else if (type == 1) {
								that.send_photo.push(apiresult.data.url);
							}
							console.log(apiresult.data.url);
						} else {
							uni.showToast({
								title: apiresult.msg,
								icon: 'error',
								duration: 2000
							})
						}
					},
					fail() {
						uni.showToast({
							title: "网络连接失败",
							icon: 'error',
							duration: 2000
						})
					}
				});
			},
		}
	}
</script>

<style>
	.content {
		background: #F3F1F1;
		min-height: 100vh;
	}

	.xia {
		height: 1rpx;
		border-bottom: 1rpx dashed #E1DFDF;
	}
</style>